#include("/common/_layout.html")
#@layout()
#define layoutHead()
	<title>老师编辑</title>
#end
#define layoutBody()
	<body>
		<div class="page-content-wrap">
				<form class="layui-form" lay-filter="formedit">
					<input type="hidden" name="teacher_id">
					<div class="layui-tab" style="margin: 0;">
						<ul class="layui-tab-title">
							<li><a href="javascript:window.history.back();">老师列表</a></li>
							<li class="layui-this">老师编辑</li>
						</ul>
						<div class="layui-tab-content">
							<div class="layui-tab-item"></div>
							<div class="layui-tab-item layui-show">
								<div class="layui-form-item">
									<label class="layui-form-label">姓名：</label>
									<div class="layui-input-block">
										<input type="text" name="teacher_name" required lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">职务：</label>
									<div class="layui-input-block">
										<div class="layui-inline">
										<select id="post_id" name="post_id" lay-verify="required">
											<option value="">选择职务</option>
										</select>
										</div>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">手机：</label>
									<div class="layui-input-block">
										<input type="text" id="teacher_mobile" name="teacher_mobile" lay-verify="phone" placeholder="请输入手机" autocomplete="off" class="layui-input">
										<div style="font-size:12px;color:#404040;margin:5px;">注：手机号默认为【登录账户】，请输入真实有效的手机号，创建后不可更改</div>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">登录密码：</label>
									<div class="layui-input-block">
										<input type="password" name="user_pwd" placeholder="不修改，请置空" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">所在班级：</label>
									<div class="layui-input-block">
										<select id="class_id" name="class_id" lay-verify="required" lay-filter="class_id">
											<option value="">请选择班级</option>
										</select>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">老师状态：</label>
									<div class="layui-input-block">
										<select name="teacher_stateid" lay-verify="required">
											<option value="1">启用</option>
											<option value="0">禁用</option>
										</select>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="layui-form-item" style="padding-left: 10px;">
						<div class="layui-input-block">
							<button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo">立即提交</button>
							
						</div>
					</div>
				</form>
		</div>
		<script src="/static/js/jquery.formHelp.js" type="text/javascript" charset="utf-8"></script>
		<script>

			layui.use(['form', 'layer', 'laytpl'], function() {
				var form = layui.form();
				var layer = layui.layer;
				var laytpl = layui.laytpl;
				// 表单验证
				form.verify({
					username: function(value, item){ //value：表单的值、item：表单的DOM对象
						if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
							return '老师名不能有特殊字符';
						}
						if(/(^\_)|(\__)|(\_+$)/.test(value)){
							return '老师名首尾不能出现下划线\'_\'';
						}
						if(/^\d+\d+\d$/.test(value)){
							return '老师名不能全为数字';
						}
					}
					,passwd: [
						/^[\S]{6,12}$/
						,'密码必须6到12位，且不能出现空格'
					] 
				});

				//监听提交
				form.on('submit(formDemo)', function(formData){

					sendPost("/api/eduorg/teacher/save", formData.field, function(res) {
						layer.alert(res.msg, {
							title: '信息提示'
						}, function(idx){
							if (res.code==200){
								window.history.back();;
							}
							layer.close(idx);
						});
					});
					return false;
				});

				// 页面初始化
				function page_init(){
					var id = getUrlParam('id');
					if (id===null || id === 'undefined' || id<=0){
						$("[name='user_pwd']").attr("lay-verify","passwd").attr("placeholder","请输入密码");
					}
					// 加载初始化编辑数据
					sendGet("/api/eduorg/teacher/getOne", {
						id : getUrlParam("id")
					}, function(res) {
						//console.log(res);
						// 初始化编辑数据
						if (res.hasOwnProperty("listpost")) {
							bindSelectJSONProps("post_id", res, "listpost", "post_name", "post_id", 2);
						}
						if (res.hasOwnProperty("listclass")) {
							bindSelectJSONProps("class_id", res, "listclass", "class_name", "class_id", "");
						}
						if (res.hasOwnProperty("oneinfo")) {
							$("form.layui-form").setForm(res.oneinfo);
							$('#teacher_mobile').attr('readonly','');
						}
						form.render();
					});
				}

				page_init();
			});
		</script>
	</body>

#end